package flywieight.pattern.demo;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 逸足天涯
 * @create 2019-10-12 20:19
 */
public class RobotFactory {
    Map<String,IRobot> shapes = new HashMap<String,IRobot>();
    public int totalObjectCreated(){
        return shapes.size();
    }

    public IRobot getRobotFromFactory(String rc) throws Exception{
        IRobot robotCategory = null;
        if(shapes.containsKey(rc)){
            robotCategory = shapes.get(rc);
        } else{
            switch (rc){
                case "small":
                    System.out.println("We do not have small Robot.So we are creating a Small Robot now.");
                    robotCategory = new SmallRobot();
                    shapes.put("small",robotCategory);
                    break;
                case "large":
                    System.out.println("We do not have Large Robot.So we are creating a Large Robot now.");
                    robotCategory = new LargeRobot();
                    shapes.put("larrg",robotCategory);
                    break;
                 default:
                     throw new Exception("Robot Factory can create only small and large shapes");
            }
        }
        return  robotCategory;
    }

}